using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace GempGame
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Building : Microsoft.Xna.Framework.GameComponent
    {
        public enum Name
        {
            NONE,
            HOME,
            BANK,
            CHURCH,
            FACTORY,
            OFFICE
        }

        public Name buildingName;

        SpriteBatch spriteBatch;
        Texture2D buildingTexture;

        String texturePath;
        public Rectangle buildingRect {get; set;}

        bool mouseOver = false;

        public Building(Game game, Name buildingName, String texturePath, int posX, int posY, int width, int height)
            : base(game)
        {
            this.buildingName = buildingName;
            this.texturePath = texturePath;
            this.buildingRect = new Rectangle(posX, posY, width, height);
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            base.Initialize();
        }

        public void LoadContent()
        {
            
            buildingTexture = Game.Content.Load<Texture2D>(this.texturePath);
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            if (buildingRect.Intersects(new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1)))
            {
                mouseOver = true;
            }
            else
            {
                mouseOver = false;
            }

            base.Update(gameTime);
        }

        public void Draw(GameTime gameTime)
        {
            int alphaValue = 255;

            if (mouseOver)
            {
                alphaValue = 150;
            }

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            spriteBatch.Draw(this.buildingTexture, this.buildingRect, new Color(255, 255, 255, alphaValue));
            spriteBatch.End();
        }
    }
}
